import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 当前所在dd-nav
    currentDdNav: window.sessionStorage.getItem('currentDdNav') || '首页',
    // 当前音乐信息
    currentMusic: JSON.parse(window.sessionStorage.getItem('currentMusic')) || null,
    // 当前音乐url
    currentMusicUrl: window.sessionStorage.getItem('currentMusicUrl') || '',
    // 当前音乐的总时长
    currentSongAlltimer: window.sessionStorage.getItem('currentSongAlltimer') || 0,
    // 当前播放队列
    currentSongList: JSON.parse(window.sessionStorage.getItem('currentSongList')) || []
  },
  mutations: {
    // 设置当前所在dd-nav
    setCurrentDdNav(state, nav) {
      state.currentDdNav = nav;
      window.sessionStorage.setItem('currentDdNav', nav);
    },
    // 设置当前音乐信息
    setCurrentMusic(state, info) {
      state.currentMusic = info;
      window.sessionStorage.setItem('currentMusic' ,JSON.stringify(info));
    },
    // 设置当前音乐url
    setCurrentMusicUrl(state, url) {
      state.currentMusicUrl = url;
      window.sessionStorage.setItem('currentMusicUrl', url);
    },
    // 设置当前音乐的总时长
    setSongAllTimer(state, time) {
      state.currentSongAlltimer = time;
      window.sessionStorage.setItem('currentSongAlltimer', time);
    },

    // 设置当前播放队列
    setCurrentSongList(state, list) {
      state.setCurrentSongList = list;
      window.sessionStorage.setItem('currentSongList', JSON.stringify(list));
    }
  },
  actions: {
  },
  modules: {
  }
})
